/*
 * DiscoveryPresenter.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.discovery.page;

import com.yidiandao.business.data.model.DiscoveryModel;
import com.yidiandao.business.data.model.IDiscoveryModel;
import com.yidiandao.business.data.response.DiscoveryItemTypeResponse;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;

import java.util.List;

/**
 * 发现-Presenter
 * <p>
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/8 15:40
 */
public class DiscoveryPagePresenter implements DiscoveryPageContract.Presenter {

    private final DiscoveryPageContract.View mDiscoveryView;

    private IDiscoveryModel mDiscoveryModel;

    public DiscoveryPagePresenter(DiscoveryPageContract.View view) {
        mDiscoveryView = view;
        mDiscoveryModel = new DiscoveryModel();

        mDiscoveryView.setPresenter(this);
    }

    @Override
    public void start() {
        loadDiscoveryData();
    }

    @Override
    public void loadDiscoveryData() {

        mDiscoveryModel.loadItemTitle(mDiscoveryView.getPagerTag(), mDiscoveryView.getTypeId() + "", new IDiscoveryModel.OnAccessNetListener<List<DiscoveryItemTypeResponse.DataBean.CatListBean>>() {
            @Override
            public void onSuccess(List<DiscoveryItemTypeResponse.DataBean.CatListBean> catListBeen) {
                mDiscoveryView.refreshContent(mDiscoveryView.checkResultObject(catListBeen));
                mDiscoveryView.setTitleList(catListBeen);
            }

            @Override
            public void onFailed() {
                mDiscoveryView.refreshContent(SuperLoadingLayout.STATE_ERROR);
            }

            @Override
            public void onFinal() {

            }
        });

    }
}
